﻿using System;
using UnityEngine;
using UnityEngine.UIElements;

namespace winS.UnityEditor.UIElement
{
    public static class VisualElementExtension
    {
        public static void SetPosition(this VisualElement self, Vector2 position)
        {
            if (self.style.position != Position.Absolute) throw new Exception($"{nameof(SetPosition)}: 仅当 style.position 为 Position.Absolute 时才可调用该方法");
            self.style.left = position.x;
            self.style.top = position.y;
        }
        public static Vector2 GetPosition(this VisualElement self)
        {
            return new Vector2(self.style.left.value.value, self.style.top.value.value);
        }

        public static Row AddPostfix(this VisualElement self, string postfix)
        {
            return EditorElementUtility.AddPostfix(self, postfix);
        }
        public static Row ToNonExpandRow(this VisualElement self, float width, float flexGrow = 1f)
        {
            return EditorElementUtility.CreateNonExpandRow(self, width, flexGrow);
        }
        public static void AsButton(this VisualElement self, Action clickCallback)
        {
            EditorElementUtility.RegisterClickEvent(self, clickCallback);
        }
    }
}